<!DOCTYPE html>
<html>
	<head>
		<title>用户管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="pragma" content="no-cache" />
		<link rel="stylesheet" type="text/css" href="/js/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css">
		<script type="text/javascript" src="/js/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>

		$(function(){
					
			/*表格初始化*/
			$("#grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
			    columns:[[    
			    	{field:'CK',checkbox:true},
			        {field:'role_code',title:'角色编码',width:100,align:'center'},    
			        {field:'role_name',title:'角色名称',width:100,align:'center'}
			    ]],
			    url:'/admin/roleManagement/getRoles',
			    toolbar:[{
			    	text:'查询',
					iconCls:'icon-search',
					handler: function(){ 
						$("#grid").datagrid('reload');
					}
			    },'-',{
			    	text:'新增',
					iconCls:'icon-add',
					handler: function(){ 
						$("#add_dialog").dialog({ 
							title: '添加角色',    
							width: 400,    
							height: 200,    
							closed: false,    
							modal: true,
							buttons:[{
								text:'保存',
								iconCls:'icon-save',
								handler:function(){
									$('#add_form').form('submit', {    
										 url:"/admin/roleManagement/insertRole", 
										 success:function(response){   
											response=JSON.parse(response);
											if(response.state==200){
											   if(response.data==1){
												   $.messager.alert('提示','添加成功');
												   $("#add_dialog").dialog("close");
												   $("#grid").datagrid('reload');
											   }else{
												   $.messager.alert('提示','添加失败');
											   }
											}else{
											   $.messager.alert('警告','操作失败');
											}   
										 }  
									});
									
								}
							}]
						})
					}
			    },'-',{
			    	text:'修改',
			    	iconCls:'icon-edit',
			    	handler: function(){ 
			    		var rows = $('#grid').datagrid('getSelections');
						$("#edit_role_id").textbox('setValue',rows[0].role_id);
						$("#edit_role_code").textbox('setValue',rows[0].role_code);
						$("#edit_role_name").textbox('setValue',rows[0].role_name);
						
			    		$("#edit_dialog").dialog({ 
			    			title: '修改角色',    
							width: 400,    
							height: 200,    
							closed: false,    
							modal: true,
							buttons:[{
								text:'保存',
								iconCls:'icon-save',
								handler:function(){
									
									
									$('#edit_form').form('submit', {
										 url:"/admin/roleManagement/updateRole", 
										 success:function(response){
											 response=JSON.parse(response);
											 if(response.state==200){
												   $.messager.alert('提示','修改数据'+response.data+'条');
												   $("#edit_dialog").dialog("close");
												   $("#grid").datagrid('reload');
											}else{
												   $.messager.alert('警告','操作失败');
											}
										 }
									})
								}
							}]
			    		});
			    	}
			    },'-',{
			    	text:'配置菜单',
			    	handler: function(){
			    		$("#config_menu_dialog").dialog({
			    			title: '菜单配置',    
							width: 400,    
							height: 200,    
							modal: true
			    		});
			    		var rows = $('#grid').datagrid('getSelections');
						
			    		$("#menu_tree").tree({    
			    		    url:'/admin/roleManagement/getMenusByRoleCode?role_code='+ rows[0].role_code,  
			    		    onContextMenu: function(e, node){
			    		    	//alert(node.attributes);
			    				e.preventDefault();
			    				// 查找节点
			    				$('#tt').tree('select', node.target);
			    				// 显示快捷菜单
			    				$('#tree_right_menu').menu('show', {
			    					left: e.pageX,
			    					top: e.pageY
			    				});

			    			}

			    		});  

			    	} 
			    }]

			});
			
		
		});
			
		</script>
	</head>
	<body class="easyui-layout">
		<!-- 主表格 -->
		<div region="center" border="false">
			<table id="grid" ></table>
		</div>


		<!-- 一些隐藏的对话框 -->
		<!-- 新增角色页 -->
		<div style="display:none" id="add_dialog">
			<form id ="add_form" method="post" >
				<table width="100%">
					<tr>
						<td align="right" width="20%">角色编码:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"   name="role_code" style="width:200px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">角色名称:</td>
						<td width="20%"  align="left">
							<input class="easyui-textbox"   name="role_name" style="width:200px" />
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div>
		
		<!-- 角色信息修改页 -->
		<div style="display:none" id="edit_dialog">
			<form id ="edit_form" method="post" >   
				<table width="100%">
					<tr>
						<div style="display:none">
							<input class="easyui-textbox" id="edit_role_id"  name="role_id" style="width:200px"  />
						</div>
						<td align="right" width="20%">角色编码:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox" id="edit_role_code"  name="role_code" style="width:200px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">角色名称:</td>
						<td width="20%"  align="left">
							<input class="easyui-textbox" id="edit_role_name"  name="role_name" style="width:200px" />
						</td>
						<td width="20%" ></td>
					</tr>

				</table>
			</form>
		</div> 

		<!-- 角色菜单配置页 -->
		<div style="display:none" id="config_menu_dialog">
			<ul id="menu_tree"></ul>  
		
		</div>
		
		<div id="tree_right_menu" class="easyui-menu" style="width:120px;">
			<div onclick="addSubNode()" data-options="iconCls:'icon-add'">添加子节点</div>
			<div onclick="addSubPage()" data-options="iconCls:'icon-add'">添加子页面</div>
			<div onclick="remove()" data-options="iconCls:'icon-remove'">移除当前</div>
		</div>
		
	</body>
</html>
